package app.tvprogram;

import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;

public class TvProgramTable extends JTable {
    Object[] realTableHeaderData;
    Object[][] realTableData;
    private static int additionalCol = 2;

    public TvProgramTable() {
        super();
    }

    public void repopulateWithData(Object[] tableHeaderData,
            Object[][] tableData) {
        if (tableHeaderData != null && tableHeaderData.length > 0) {
            realTableHeaderData = new Object[tableHeaderData.length
                    + additionalCol];
            realTableHeaderData[0] = Constants.label_sequence;
            realTableHeaderData[1] = Constants.label_time;
            System.arraycopy(tableHeaderData, 0, realTableHeaderData, 2,
                    tableHeaderData.length);
        }
        if (tableData != null && tableData.length > 0) {
            realTableData = new Object[tableData.length][realTableHeaderData.length];
            for (int i = 0; i < tableData.length; i++) {
                realTableData[i][0] = i + 1;
                String timeStr = "0" + i + ":00";
                if (i >= 10) {
                    timeStr = i + ":00";
                }
                realTableData[i][1] = timeStr;
                System.arraycopy(tableData[i], 0, realTableData[i], 2,
                        tableData[i].length);
            }

        }
        TableModel jTable1Model = new DefaultTableModel(realTableData,
                realTableHeaderData);
        this.setModel(jTable1Model);
        if (tableData != null && tableData.length > 0) {
            this.getTableHeader().getColumnModel().getColumn(0).setMaxWidth(20);
            this.getTableHeader().getColumnModel().getColumn(0).setMinWidth(20);
            this.getColumnModel().getColumn(0).setMaxWidth(20);
            this.getColumnModel().getColumn(0).setMinWidth(20);
        }
    }
}
